package quick

import (
	"sync"
	"t_sort/data"
)

func Sort[T data.SortType](arr []T) {
	if len(arr) <= 1 {
		return
	}

	mark := 0
	mu := sync.Mutex{}

	for i := 1; i < len(arr); i++ {
		if arr[0] > arr[i] {
			mark++
			if mark == i {
				continue
			}
			mu.Lock()
			data.Count++
			mu.Unlock()

			arr[mark], arr[i] = arr[i], arr[mark]
		}
	}
	arr[0], arr[mark] = arr[mark], arr[0]

	Sort(arr[:mark])
	Sort(arr[mark+1:])

}
